import { ServerResponse, IncomingMessage } from "http";
/**
 * http响应
 * @remarks
 * 在ServerResponse基础上增加了写客户端方法，更适合直接使用
 */
export class HttpResponse extends ServerResponse {
    private req: IncomingMessage;
    private res: ServerResponse;

    constructor(req: IncomingMessage) {
        this.req = req;
    }

    public init(req: IncomingMessage, res: ServerResponse): void {
        this.res = res;
        // Initialize response headers or perform any other required setup
    }
}
// Example usage:
const server = http.createServer((req, res) => {
    const httpRequest = new HttpRequest(req, res);
    httpRequest.init()
      .then((parameters) => {
        // Handle the request with the initialized parameters
        console.log('Parameters:', parameters);
        httpRequest.response.send('Response data');
      })
      .catch((error) => {
        console.error('Error:', error);
        httpRequest.response.sendError(500, 'Internal Server Error');
      });
  });
  
  server.listen(3000, () => {
    console.log('Server is running on port 3000');
  });